<?php
/**
 * 个人资料
 * @author zelome@163.com
 * $Id: index.php 10 2011-02-23 07:01:48Z sbnnest@gmail.com $
 */

require_once('../common.inc.php');

class person extends Action
{
	
	/**
	 * 获取个人资料
	 */
	function doDefault()
	{
		$page = $this->app->page();
		$page->params['template'] = 'content/person.tpl';

		$sbn_user = $_SESSION['sbn_user'];
		
		$db_r = $this->app->orm ()->query ();
		$db_r->addTable ( 'tb_user' );
		$db_r->addField ( 'user_id' );
		$db_r->addField ( 'user_name' );
		$db_r->addField ( 'user_nickname' );
		$db_r->addField ( 'user_sex' );
		$db_r->addField ( 'user_password' );
		$db_r->addWhere ( 'user_name', $sbn_user );
		
		$result = $db_r->getRow ();
		$page->value ( 'user_id', $result ['user_id'] );
		$page->value ( 'username',$result ['user_name'] );
		$page->value ( 'password', $result ['user_password'] );
		$page->value ( 'sex', $result ['user_sex'] );
		$page->value ( 'nickname', $result ['user_nickname'] );
		
		$page->output ();
	}
	
	/**
	 * 修改个人资料
	 */
	function  doModify(){
		$page = $this->app->page();
		$page->params['template'] = 'content/person.tpl';

		$sbn_user = $_SESSION['sbn_user'];
		$db_r = $this->app->orm ()->query ();
		
		$nickname = trim($_POST['nickname']);
		$password = trim($_POST['password']);
		$usersex = trim($_POST['usersex']);
		$db_r->addTable ( 'tb_user' );
		$db_r->addField ( 'user_id' );
		$db_r->addField ( 'user_name' );
		$db_r->addField ( 'user_nickname' );
		$db_r->addField ( 'user_sex' );
		$db_r->addField ( 'user_password' );
		$db_r->addWhere ( 'user_name', $sbn_user );
		$db_r->update ( array ('user_nickname' => $nickname, 'user_password' => $password ,'user_sex'=>$usersex) );

		
		$result = $db_r->getRow ();
		$page->value ( 'user_id', $result ['user_id'] );
		$page->value ( 'username',$result ['user_name'] );
		$page->value ( 'password', $result ['user_password'] );
		$page->value ( 'sex', $result ['user_sex'] );
		$page->value ( 'nickname', $result ['user_nickname'] );
		
		$page->output ();
	}
}
											
$app->run();

?>
